<!--<!DOCTYPE html>

<html>

	<head>
		<meta charset="utf-8">
		<title>车协官网后台管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">

		<link rel="stylesheet" href="/admin/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/admin/css/global.css" media="all">
		<link rel="stylesheet" href="/admin/plugins/font-awesome/css/font-awesome.min.css">

	</head>

	<body>
		<div class="layui-layout layui-layout-admin">
			<div class="layui-header header header-demo">
				<div class="layui-main">
					<div class="admin-login-box">
						<a class="logo" style="left: 0;" href="http://beginner.zhengjinfan.cn/demo/beginner_admin/">
							<span style="font-size: 22px;">后台管理</span>
						</a>
						<div class="admin-side-toggle">
							<i class="fa fa-bars" aria-hidden="true"></i>
						</div>
					</div>
					<ul class="layui-nav admin-header-item">
						<li class="layui-nav-item">
							<span>欢迎您<%=host%>:</span>
						</li>
						<li class="layui-nav-item">
							<a href="/" target="_blank">浏览网站</a>
						</li>
						<li class="layui-nav-item" >
							<a href="/logout"><i class="fa fa-sign-out"></i> 注销</a>
						</li>

					</ul>

				</div>
			</div>
			<div class="layui-side layui-bg-black" id="admin-side">
				<div class="layui-side-scroll" id="admin-navbar-side" lay-filter="side"></div>
			</div>
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;" id="admin-body">
				<div class="layui-tab admin-nav-card layui-tab-brief" lay-filter="admin-tab">
					<ul class="layui-tab-title">
						<li class="layui-this">
							<i class="fa fa-dashboard" aria-hidden="true"></i>
							<cite>主页</cite>
						</li>
					</ul>-->
					<%include common/include_header.html%>
					<div class="layui-tab-content" style="min-height: 150px; padding: 5px 0 0 0;">
						<div>
							<div class="admin-main">

		<blockquote class="layui-elem-quote">
			<a href="javascript:;" class="layui-btn layui-btn-small" id="refresh">
				刷新数据
			</a>

		</blockquote>
		<fieldset class="layui-elem-field">
			<legend>数据列表</legend>
			<div class="layui-field-box">
				<table class="site-table table-hover">
					<thead>
					<tr>
						<th>序号</th>
						<th>标题</th>
						<th>查看内容</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody id="tabContent">

					</tbody>
				</table>

			</div>
		</fieldset>
		<div class="admin-table-page">
			<div id="page" class="page">
			</div>
		</div>
	</div>
						</div>
					</div>
				
			<%include common/include_footer.html%>
			<!--<div class="layui-footer footer footer-demo" id="admin-footer">
				<div class="layui-main">
					<p>2018 &copy;
						<a href="/">惠升后台管理系统</a> LGPL license
					</p>
				</div>
			</div>
			<div class="site-tree-mobile layui-hide">
				<i class="layui-icon">&#xe602;</i>
			</div>-->

			<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
			<script type="text/javascript" src="/admin/plugins/layui/layui.js"></script>
			<!--<script type="text/javascript" src="/admin/datas/nav.js"></script>-->
			<script src="/admin/js/index1.js"></script>
			<script>
				layui.config({
			base: 'plugins/layui/modules/'
		});

		layui.use(['icheck', 'laypage','layer'], function() {
			var $ = layui.jquery,
					laypage = layui.laypage,
					layer = parent.layer === undefined ? layui.layer : parent.layer;


			//页面初始化的时候执行
			$(function (){
				getData(1);
			});

			//点击刷新按钮
			$('#refresh').on('click', function() {
				getData(1);
				layer.msg('刷新成功');
			});

			//查看新闻详情
			$('#tabContent').on('click', '.layui-btn-normal', function() {
				var obj = $(this);
				var id = obj.parents('tr').attr('id');
				$.post("/admin/company_content",{id:id},function(result){
					if(result.status==="success"){
						var content=result.data;
						//驾驶证信息弹窗
						layer.open({
							type: 1 //Page层类型
							,area: ['1000px', '800px']
							,title: '详情'
							,shade: 0.6 //遮罩透明度
							,maxmin: true //允许全屏最小化
							,anim: 1 //0-6的动画形式，-1不开启
							,content: content
						});
					}else{
						layer.msg('获取信息失败!', {
							icon: 1,
							time: 1000
						});
					}
				});
			});
			/*编辑分类*/
			$('#tabContent').on('click', '.edit', function() {
				var obj = $(this);
				var id = obj.parents('tr').attr('id');

				layer.confirm('确认要编辑吗？', {
					icon: 0,
					title: '提示',
					shade: false
				}, function(index) {
					location.href="/admin/edit_company_information/"+id
				});
			});
			
			/*删除分类*/
			$('#tabContent').on('click', '.layui-btn-danger', function() {
				var obj = $(this);
				var id = obj.parents('tr').attr('id');

				layer.confirm('确认要删除吗？', {
					icon: 0,
					title: '警告',
					shade: false
				}, function(index) {

					$.post("/admin/company_news_del",{id:id},function(result){
						if(result.status==="success"){
							$(obj).parents("tr").remove(); //删除方法
							layer.msg('已删除!', {
								icon: 1,
								time: 1000
							});
							getData(1);
						}else{
							layer.msg('删除失败!', {
								icon: 1,
								time: 1000
							});
						}
					});
				});
			});


			//从后台获取数据函数，获取页数curr的数据
			function getData(curr){
				$.post("/admin/get_company_information",{curr:curr},function(result){
					//拼接html内容
					var tabContent="";
					//获取后台json数据
					var mydata=result.data;


					for(var i=0;i<mydata.length;i++){
						if(mydata[i].category==='0'){
							category='<span class="layui-btn layui-btn-primary layui-btn-mini">企业动态</span>';
						}else{
							category='<span class="layui-btn layui-btn-primary layui-btn-mini">关于我们</span>';
						}

						var tempStr='<tr id='+mydata[i]._id+'>'+
									/*序号分页后也必须得变动,每页十条数据*/
								'<td>'+(i+(curr-1)*10+1)+'</td>'+
								'<td>'+mydata[i].title+'</td>'+
								'<td>'+
								'<span class="layui-btn layui-btn-normal layui-btn-mini">查看内容</span>'+
								'</td>'+
								'<td>'+
								'<span class="layui-btn layui-btn-mini edit" style="margin-right:5px">编辑</span>'+
								 <% if (isSuper =="超级管理员") { %>
								 	'<span class="layui-btn layui-btn-danger layui-btn-mini">删除</span>'+
           						<% } %>
								'</td>'+
								'</tr>'
						tabContent=tabContent+tempStr;
					}
					//将拼接好的数据填入#tabContent中
					$("#tabContent").html(tabContent);
					//显示分页
					laypage({
						cont: 'page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
						pages: result.pages, //通过后台拿到的总页数
						curr: curr || 1, //当前页
						jump: function(obj, first){ //触发分页后的回调
							if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
								getData(obj.curr);
							}
						}
					});

				});
			};

		});
			</script>
			<style>.admin-table-page .page .layui-laypage {
    margin: 6px 0 0 0;
    padding-left: 500px;
}</style>
		</div>
	</body>

</html>